package com.aidex.business.service.apiService.impl;

import com.aidex.business.config.BizConfig;
import com.aidex.business.service.apiService.intfc.IIasApiService;
import com.aidex.common.exception.BizException;
import com.aidex.common.utils.StringUtils;
import com.aidex.common.utils.http.HttpUtils;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class IasApiServiceImpl implements IIasApiService {

    @Autowired
    private BizConfig bizConfig;

    @Value(value = "${business.ias.endpoint}")
    private String IasEndpoint;

    @Override
    public String verifyboundvalue(Map<String, String> params) throws BizException {
        String url = IasEndpoint + "/v1.0/login/verifyboundvalue";
        params.put("businessOrgCode", bizConfig.getOrgCode());
        params.put("businessSystemCode", bizConfig.getSysCode());
        params.put("businessSystemAppID", bizConfig.getSysAppId());
        String rspStr = "";
        try {
            rspStr = HttpUtils.sendPost(url, JSONObject.toJSONString(params));
        } catch (Exception e) {
            throw new BizException("请求医院统一认证服务异常，" + e.getMessage());
        }
        if (StringUtils.isEmpty(rspStr)) {
            throw new BizException("医院统一认证服务响应异常，返回数据为空");
        }
        return rspStr;
    }
}
